/*
 * This is the interface to define a method to implement in sub-classes.
 * All sub classes of this class should define how allocate components to Component Servers.
 */
package sdc.strategy.allocation;

import java.util.List;
import sdc.Address;
import sdc.ServiceBroker;
import sdc.component.type.ComponentType;
import sdc.net.server.comp.ComponentServer;
import sdc.net.server.comp.ComponentServerManager;
import sdc.overlay.InitialOverlayConstructor;

/**
 *
 * @author yokoe
 */
public abstract class AllocateStrategy
{

	/**
	 * A method to allocate components to Component Server.
	 * @param type
	 * @param duplicateNum
	 */
	public abstract List<ComponentServer> allocateComponents(ComponentType type, int duplicateNum);

	/**
	 * 
	 * @param componentServer
	 * @param componentType
	 */
	protected final void allocateComponentToServer(ComponentServer componentServer, ComponentType componentType)
	{
		InitialOverlayConstructor.startConstructingOverlay(componentServer, componentType);

		ServiceBroker.INSTANCE.addNewAddress(componentServer.getAddress(), componentType);
	}

	public void allocateComponentToAddress(Address address, ComponentType componentType)
	{
		ComponentServer componentServer =  ComponentServerManager.INSTANCE.get(address);
		allocateComponentToServer(componentServer, componentType);
	}
}
